<?xml version="1.0" encoding="ISO-8859-1"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                template="template.xhtml">
    <ui:define name="body">
        <h:form>
            <p:panel header="Mails">
                <p:messages/>
                <p:dataTable id="mailsTable" 
                             value="#{mailListView.mailsList}" var="_mail" rowIndexVar="_row" 
                             selection="#{mailListView.selectedMail}" selectionMode="single"
                             rows="5" paginator="true" update="@form">

                    <p:column headerText="from">
                        #{_mail.fromTo.from.toString()}
                    </p:column>
                    <p:column headerText="date">
                        <h:outputText value="#{_mail.date}">
                            <f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>
                        </h:outputText>
                    </p:column>
                    <p:column headerText="subject">
                        #{_mail.subject}
                    </p:column>
                </p:dataTable>

                <ui:include src="mail_view_component.xhtml"/>

            </p:panel>
            <p:panel header="actionsPanel" >            
                <p:commandButton value="Delete" actionListener="#{mailListActions.delete(mailListView.selectedMail)}" update="@form" disabled="#{mailListView.selectedMail == null}"/>
                <p:commandButton value="Delete all" actionListener="#{mailListActions.deleteAll()}" update="@form" disabled="#{mailListView.selectedMail == null}"/>
                <p:commandButton value="New message" action="mail_edit.xhtml?faces-redirect=true" actionListener="#{mailListActions.startNew()}" ajax="false" />
                <p:commandButton value="Reply message" action="mail_edit.xhtml?faces-redirect=true" actionListener="#{mailListActions.startReply(mailListView.selectedMail)}" ajax="false" disabled="#{mailListView.selectedMail == null}"/>
                <p:commandButton value="Forward message" action="mail_edit.xhtml?faces-redirect=true" actionListener="#{mailListActions.startForward(mailListView.selectedMail)}" ajax="false" disabled="#{mailListView.selectedMail == null}"/>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
